fix(server): add backpressure to SSE event queues#19423
Open
BYK wants to merge 1 commit intoanomalyco:devfrom
Open
fix(server): add backpressure to SSE event queues#19423BYK wants to merge 1 commit intoanomalyco:devfrom
BYK wants to merge 1 commit intoanomalyco:devfrom
Conversation
This was referenced Mar 28, 2026
a590ccd to
655f1a9
Compare
AsyncQueue is unbounded — when SSE clients fall behind (slow network, stalled browser tab), JSON-serialized bus events accumulate without limit. This caused 187GB RSS in production (anomalyco#16697). Add optional capacity parameter to AsyncQueue with drop-oldest behavior. Set to 1024 items (~2MB) for both SSE endpoints. TUI queues remain unbounded (1:1 request/response, never accumulate).
655f1a9 to
2631130
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #16697
Type of change
What does this PR do?
Adds backpressure to the
AsyncQueueused by SSE endpoints to prevent unbounded memory growth when clients fall behind.Root cause:
AsyncQueuehas no size limit. When an SSE client stalls (slow network, backgrounded tab, stalled proxy),Bus.subscribeAllkeeps pushingJSON.stringify'd events into the queue without bound. In production this caused 187GB RSS (forensic report).Fix: Add optional
capacityparameter toAsyncQueuewith drop-oldest behavior. When the queue exceeds capacity, oldest items are discarded. Set to 1024 items (~2MB at ~2KB avg event size) for both SSE endpoints (event.tsandglobal.ts). TUI queues remain unbounded since they are 1:1 request/response pairs that never accumulate.The web UI already handles reconnection gracefully (full state reload on
server.connected), so dropped events during a stall are recovered naturally.3 files changed, ~7 lines.
How did you verify your code works?
Checklist